package com.xqb.modules.controller.market;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.dto.MktUserCouponDto;
import com.xqb.modules.domain.po.MktUserCoupon;
import com.xqb.modules.service.IMktUserCouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 领取优惠券的记录Controller
 * 
 * @author xqb
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/market/user_coupon")
@Slf4j
public class MktUserCouponController extends BaseController
{
    @Autowired
    private IMktUserCouponService mktUserCouponService;

    /**
     * 查询领取优惠券的记录列表
     */
    @PreAuthorize("@ss.hasPermi('market:user_coupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(MktUserCoupon mktUserCoupon)
    {
        startPage();
        List<MktUserCoupon> list = mktUserCouponService.selectMktUserCouponList(mktUserCoupon);
        return getDataTable(list);
    }

    /**
     * 导出领取优惠券的记录列表
     */
    @PreAuthorize("@ss.hasPermi('market:user_coupon:export')")
    @Log(title = "领取优惠券的记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MktUserCoupon mktUserCoupon)
    {
        List<MktUserCoupon> list = mktUserCouponService.selectMktUserCouponList(mktUserCoupon);
        ExcelUtil<MktUserCoupon> util = new ExcelUtil<MktUserCoupon>(MktUserCoupon.class);
        util.exportExcel(response, list, "领取优惠券的记录数据");
    }

    /**
     * 获取领取优惠券的记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:user_coupon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mktUserCouponService.selectMktUserCouponById(id));
    }

    /**
     * 新增领取优惠券的记录
     */
    @PreAuthorize("@ss.hasPermi('market:user_coupon:add')")
    @Log(title = "领取优惠券的记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MktUserCoupon mktUserCoupon)
    {
        return toAjax(mktUserCouponService.insertMktUserCoupon(mktUserCoupon));
    }

    /**
     * 修改领取优惠券的记录
     */
    @PreAuthorize("@ss.hasPermi('market:user_coupon:edit')")
    @Log(title = "领取优惠券的记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MktUserCoupon mktUserCoupon)
    {
        return toAjax(mktUserCouponService.updateMktUserCoupon(mktUserCoupon));
    }

    /**
     * 删除领取优惠券的记录
     */
    @PreAuthorize("@ss.hasPermi('market:user_coupon:remove')")
    @Log(title = "领取优惠券的记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mktUserCouponService.deleteMktUserCouponByIds(ids));
    }

    /**
     * 获取用户可使用优惠劵
     */
    @PreAuthorize("@ss.hasPermi('market:user_coupon:list')")
    @GetMapping("/useList")
    public AjaxResult useList(MktUserCouponDto mktCoupon) {
        log.info("获取用户可使用优惠劵入参：{}", mktCoupon);
        return success(mktUserCouponService.getUseCouponList(mktCoupon));
    }

}
